const pages = import.meta.glob('@/views/pages/**/**.vue')

console.log(pages)
import router from '@/router/index'
import type { RouteRecord } from 'vue-router'

export function addRoute(list: any[]) {
  list.forEach((v: any) => {
    router.addRoute('index', {
      path: v.url,
      name: v.url,
      component: pages['/src/views' + v.url + '.vue'], //  找到这个组件
      meta: {
        menu_id: v.menu_id,
        dynamic: true
      },
      children: []
    })

    if (v.children.length) {
      addRoute(v.children)
    }
  })
}

export function removeRoute() {
  router.getRoutes().forEach((v: RouteRecord) => {
    if (v.meta.dynamic) {
      router.removeRoute(v.name as string)
    }
  })
}
